//
// Created by hay boy on 2022/6/28.
//

#ifndef ALGORITHMS_SWITCHBOXWIRING_H
#define ALGORITHMS_SWITCHBOXWIRING_H
#include "../stack/ArrayStack.h"
bool checkBox(const int net[],int n);
bool checkBox(const int net[],int n){
    //net[0,,,n-1]为管脚数组，用以形成网组
    //n是管脚个数
    auto* s = new ArrayStack<int>(n);
    for(int i = 0;i<n;i++){
        if(!s->empty()){
            if(net[i]==net[s->top()]){
                s->pop();
            }else{
                s->push(i);
            }
        }else{
            s->push(i);
        }
    }
    if(s->empty()){
        cout<<"Switch box is routable"<<endl;
        return true;
    }
    cout<<"Switch box is not routable"<<endl;
    return false;
}
#endif //ALGORITHMS_SWITCHBOXWIRING_H
